package cn.com.pansky.sdk;

import cn.com.pansky.util.EncryptionUtils;
import cn.com.pansky.util.HttpsUtils;
import cn.com.pansky.util.PropertiesUtil;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
public class OpenApiCommunicateHelper {

	
	//正式地址
//	private static String SERVER_HOST = "http://10.189.139.11:7003//CXJM/";
//	private static String SERVER_HOST = "http://10.189.139.30:9201/CXJM/";
//	private static String SERVER_HOST = "http://10.189.139.31:6104/CXJM/";
	private final static String SERVER_HOST = PropertiesUtil.getValue("WEBSERVER_HOST");
	
	/**
	 * 返回API对应的JSONObject，如果code!=0, 直接抛出异常信息
	 * @param apipath
	 * @param params
	 * @return
	 */
	public static JSONObject send(String apipath, JSONObject param){
		JSONObject map = new JSONObject();
		map.put("PARAM", param.toString().replaceAll("\'", "").replace("\\", "").replace("\"{", "{").replace("}\"", "}"));
		map.put("SECRETKEY", EncryptionUtils.md5(param.getString("AAC002")));
		String json = HttpsUtils.post(SERVER_HOST+apipath, "json="+map.toString().replace("\\", "").replace("\"{", "{").replace("}\"", "}"));
		JSONObject obj = JSON.parseObject(json);
		return obj;
	}

}
